package com.jk.smartelderlycare.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jk.smartelderlycare.dao.SysHomestayMapper;
import com.jk.smartelderlycare.dto.SysHomestay;
import com.jk.smartelderlycare.pojo.PagedResponse;
import com.jk.smartelderlycare.service.SysHomestayService;
import com.jk.smartelderlycare.utils.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hhk
 * @version 1.0
 * @ClassName SysHomestayServiceImpl
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/11/25 16:51
 */
@Service
public class SysHomestayServiceImpl implements SysHomestayService {
    @Autowired
    private SysHomestayMapper sysHomestayMapper;
    /**
     * @description: 后端分页查询
     * @param: [sysHomestay, pageNum, pageSize]
     * @return: com.jk.smartelderlycare.pojo.PagedResponse<com.jk.smartelderlycare.dto.SysHomestay>
     * @author hhk
     * @date: 2024/11/25 16:52
     */
    @Override
    public PagedResponse<SysHomestay> findSysHomestayPaginationList(SysHomestay sysHomestay, Integer pageNum, Integer pageSize) {
        Page<SysHomestay> Page = new Page<>(pageNum,pageSize);
        QueryWrapper<SysHomestay> queryWrapper = new QueryWrapper<>();
        if(null != sysHomestay.getHomestayName() && !"".equals(sysHomestay.getHomestayName())){
            queryWrapper.like("homestay_name",sysHomestay.getHomestayName());
        }
        if(null != sysHomestay.getStartPrice() && !"".equals(sysHomestay.getStartPrice())){
            queryWrapper.ge("homestay_rent",sysHomestay.getStartPrice());

        }
        if(null != sysHomestay.getEndPrice() && !"".equals(sysHomestay.getEndPrice())){
            queryWrapper.le("homestay_rent",sysHomestay.getEndPrice());

        }

        IPage<SysHomestay> homestayIPage =  sysHomestayMapper.selectPage(Page,queryWrapper);
        return PaginationUtil.getPagedResponse(homestayIPage.getRecords(),pageNum,pageSize,homestayIPage.getTotal());
    }
    /**
     * @description: 新增
     * @param: [sysHomestay]
     * @return: void
     * @author hhk
     * @date: 2024/11/25 16:52
     */
    @Override
    public void addSysHomestay(SysHomestay sysHomestay) {
        sysHomestay.setStatus("未审核");
        sysHomestayMapper.insert(sysHomestay);
    }
    /**
     * @description: 根据id删除一条数据
     * @param: [homestayId]
     * @return: void
     * @author hhk
     * @date: 2024/11/25 16:53
     */
    @Override
    public void deleteSysHomestayById(Long homestayId) {
        sysHomestayMapper.deleteById(homestayId);
    }
    /**
     * @description: 根基id回显一条数据
     * @param: [homestayId]
     * @return: com.jk.smartelderlycare.dto.SysHomestay
     * @author hhk
     * @date: 2024/11/25 16:54
     */
    @Override
    public SysHomestay findSysHomestayById(Long homestayId) {
        return sysHomestayMapper.selectById(homestayId);
    }
    /**
     * @description: 修改民宿
     * @param: [sysHomestay]
     * @return: void
     * @author hhk
     * @date: 2024/11/25 16:54
     */
    @Override
    public void updateSysHomestay(SysHomestay sysHomestay) {
        sysHomestayMapper.updateById(sysHomestay);
    }
    /**
     * @description: 审核通过
     * @param: [sysHomestay]
     * @return: void
     * @author hhk
     * @date: 2024/11/25 16:54
     */
    @Override
    public void upPassStatusById(SysHomestay sysHomestay) {
        sysHomestayMapper.upPassStatusById(sysHomestay);
    }
/**
 * @description: 审核未通过
 * @param: [sysHomestay]
 * @return: void
 * @author hhk
 * @date: 2024/11/25 16:55
 */
    @Override
    public void FailedStatusById(SysHomestay sysHomestay) {
        sysHomestayMapper.FailedStatusById(sysHomestay);
    }


    /**
     * @description: 发布房屋列表查询
     * @param: [sysHomestay]
     * @return: java.util.List<com.jk.smartelderlycare.dto.SysHomestay>
     * @author hhk
     * @date: 2024/11/27 15:04
     */
    @Override
    public List<SysHomestay> findSysHomestayList(SysHomestay sysHomestay) {
        QueryWrapper<SysHomestay> queryWrapper = new QueryWrapper<>();
        //按照发布人查询
        queryWrapper.eq("publish_user",sysHomestay.getPublishUser());
        if( sysHomestay !=null && null != sysHomestay.getHomestayName() && !"".equals(sysHomestay.getHomestayName())){
            queryWrapper.like("homestay_name",sysHomestay.getHomestayName());
        }
        return sysHomestayMapper.selectList(queryWrapper);
    }
    /**
     * @description: 全部租房列表查询
     * @param: []
     * @return: java.util.List<com.jk.smartelderlycare.dto.SysHomestay>
     * @author hhk
     * @date: 2024/11/28 16:07
     */
    @Override
    public List<SysHomestay> fimdSysHomestayList() {
        return sysHomestayMapper.selectList(null);
    }
    /**
     * @description: 导入
     * @param: [sysHomestay]
     * @return: void
     * @author hhk
     * @date: 2024/11/30 15:17
     */
    @Override
    public void addHomestay(SysHomestay sysHomestay) {
        sysHomestayMapper.insert(sysHomestay);
    }
}
